package com.hqhy.like.front.order.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hqhy.like.common.pojo.authentication.CurrentPrincipal;
import com.hqhy.like.common.web.JsonResult;
import com.hqhy.like.front.order.pojo.param.TableUpdateInfoParam;
import com.hqhy.like.front.order.pojo.vo.TableStandardVO;
import com.hqhy.like.front.order.service.IOrderService;
import com.hqhy.like.front.order.service.ITableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/table")
@Api(tags = "2.桌台管理")
@Slf4j
public class TableController {
    @Autowired
    private ITableService tableService;

    @Autowired
    private IOrderService orderService;

    public TableController() {
        log.debug("创建控制器类对象：TableController");
    }

    @GetMapping("/list-by-available")
    @ApiOperation("查询所有空闲的桌台")
    @ApiOperationSupport(order = 300)
    public JsonResult listAllByIsAvailable(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal){
        log.debug("开始处理【查询所有空闲的桌台】的请求，当事人: {}", currentPrincipal);
        List<TableStandardVO> list = tableService.listAllByIsAvailable();
        return JsonResult.ok(list);
    }

    @PostMapping("/{tableName}/update")
    @ApiOperation("根据桌台名修改桌台数据")
    @ApiOperationSupport(order = 200)
    public JsonResult updateInfoByName(@PathVariable("tableName") String tableName, TableUpdateInfoParam tableUpdateInfoParam){
        log.debug("开始处理【根据桌台名修改桌台数据】的请求，桌台名: {}，桌台更新信息类：{}", tableName, tableUpdateInfoParam);
        tableService.updateInfoByName(tableName,tableUpdateInfoParam);
        return JsonResult.ok();
    }
}
